<?php


class NlogAdmin extends AdminBase {

	private $nohf = array('siteIndex');
	private $adhf = array("index");
	private $mongo;

	/**
	 * 构造函数
	 *
	 */
	public function __construct(){
		parent::__construct();

		if(!in_array(N_ACTION,$this->nohf)){
			n_mod('skin')->header(in_array(N_ACTION,$this->adhf)?'admin':'');
		}

		$this->mongo = n_api('mongo')->cnameAbsolute('dmslog');
	}

	public function siteIndex()
	{
		
	}

	public function info()
	{
		$param = $this->param("time:char:ignore,
								plugin:char:ignore,
								page:page");

		$time = isset($param['time']) ? strtotime($param['time']) : strtotime(date('Y-m-d'));

		$query = array(
			'time' => array(
				'$gte'=>$time,
				'$lte'=>$time+24*3600
			),
			'errtype' => 'info'
		);

		if ( isset($param['plugin']) && $param['plugin'] != '' ) {
			$query['plugin'] = $param['plugin'];
		}

		$perpage = 100;
		$page = $param['page'];
		unset($param['page']);

		$rs = $param;

		$count = $this->mongo->count('applog', $query);

		$rs['data'] = $this->mongo->find('applog', $query, '', ($page-1)*$perpage, $perpage, array('$natural'=>-1));
		
		$rs['paging'] = n_api('common')->paging(n_url('nlog', 'error', $param), $page, $count, $perpage);

		$this->_html('info', $rs);
	}

	public function error()
	{
		$param = $this->param("time:char:ignore,
								plugin:char:ignore,
								page:page");

		$time = isset($param['time']) ? strtotime($param['time']) : strtotime(date('Y-m-d'));

		$query = array(
			'time' => array(
				'$gte'=>$time,
				'$lte'=>$time+24*3600
			),
			'errtype' => 'error'
		);

		if ( isset($param['plugin']) && $param['plugin'] != '' ) {
			$query['plugin'] = $param['plugin'];
		}

		$perpage = 100;
		$page = $param['page'];
		unset($param['page']);

		$rs = $param;

		$count = $this->mongo->count('applog', $query);

		$rs['data'] = $this->mongo->find('applog', $query, '', ($page-1)*$perpage, $perpage, array('$natural'=>-1));
		
		$rs['paging'] = n_api('common')->paging(n_url('nlog', 'error', $param), $page, $count, $perpage);

		$this->_html('error', $rs);
	}

	public function testSock() {
		n_api('nlog')->errorNb('anti', 'sohublogold', 'anti_sync_error', array(
			'state' => 0,
			'msg' => 'fuckyou golang'
		));
	}

	public function __destruct(){
		if(!in_array(N_ACTION,$this->nohf)){
			//n_mod('skin')->footer(in_array(N_ACTION,$this->adhf)?'admin':'');
		}
	}	
}


?>
